package com.hori3d.rc.bean;

import java.util.ArrayList;

public class Printer {
	
	
	/**
	 * 打印机类，包括
	 * 指令、各种打印机属性、设置参数
	 *  
	 * 
	 */

	String cmdSuffix = "\r";
   
	//设置 键名
	public static String KEY_PRINTER_IP = "printer_ip";
	public static String KEY_PRINTER_PORT = "printer_port";
	public static String KEY_CAMERA_ID = "camera_id";// 当前进度
	public static String KEY_CAMERA_USERNAME = "camera_username";
	public static String KEY_CAMERA_PASSWORD = "camera_password";

	// 命令
	public static String CMD_READ_PRINTER_FIRMWARE = "M899";// 取得固件版本�?

	public static String CMD_READ_CURRENT_TEMP = "M891";// 当前温度
	public static String CMD_READ_CURRENT_SPEED = "M892";// 当前速度
	public static String CMD_READ_CURRENT_PRINTING_PROCESS = "M893";// 当前进度
	public static String CMD_READ_CURRENT_POSITION = "M894"; // 当前位置

	public static String CMD_ALL_AXIS_RESET = "G28"; // 3轴复�?
	public static String CMD_X_AXIS_RESET = "G28 X0"; // X轴复�?
	public static String CMD_Y_AXIS_RESET = "G28 Y0"; // Y轴复�?
	public static String CMD_Z_AXIS_RESET = "G28 Z0"; // Z轴复�?

	public static String CMD_PINTING_PROCESS = "M893"; // 当前打印进度
	public static String CMD_GET_SD_FILES = "M20"; // 当前打印进度

	public static String CMD_PRINTING_PAUSE = "M25"; // 暂停打印/继续打印
	public static String CMD_PRINTING_START = "M24"; // �?始打印�?�中文件
	public static String CMD_PRINTING_END = "M889"; // 终止打印文件
	
	public static String CMD_POWER_OFF = "M81"; // 打印机关机指�?
	public static String CMD_AUTO_POWER_OFF = "M882"; // 打印完成后关�?
	public static String CMD_NO_AUTO_POWER_OFF = "M883"; // 打印完成后不关机

	// 打印状�??
	public static int PRINTER_STATUS_NULL = 0; // 打印机状态未�?
	public static int PRINTER_STATUS_WARMING = 3; // 打印机加�?
	public static int PRINTER_STATUS_PRINTING = 1; // 打印机正在打�?
	public static int PRINTER_STATUS_PAUSING = 2; // 打印机状态暂�?
	public static int PRINTER_STATUS_WAITING = -1; // 打印机状态空�?

	public static int speed_pace_print = 10; // 打印速度变化�?
	public static int speed_pace_fans = 20; // 风扇速度变化�?
	public static int speed_pace_material = 1; // 出料速度变化�?
	public static int temp_pace = 5; // 温度变化�?

	
	int temp1=-1; 					// 喷头1温度
	int temp1Target=-1;			// 喷头1目标温度
	int temp2=-1; 					// 喷头2温度
	int temp2Target=-1;			// 喷头2温度
	int tempBed=-1; 				// 热床温度
	int tempBedTarget=-1;			 // 热床目标温度
 
    boolean isConnected;
	public boolean isConnected() {
		return isConnected;
	}

	public void setConnected(boolean isConnected) {
		this.isConnected = isConnected;
	}

	int printerStatusCode = PRINTER_STATUS_NULL;          // 打印状�?? ，初始为未知
	boolean isAutoPowerOff=false;                  //是否自动关机


	int printingTime = 0;					 //打印已进行时�? 单位为分�?
	int printingProcess = 0;				 //打印进度 百分�?0~100
	String printingFile = "";			     //当前正在打印的文件名

	ArrayList<String> files = new ArrayList<String>();    // SD卡文件列�?
	String pingResult = " ";                 //ping结果

	String firmwareVersion = "未知";           //打印机固件版本号

	String PRINTER_IP = "";                   //打印机ip
	int PRINTER_PORT = 0;					  //打印机端口号
							
	String cam_id = "";					   	  //摄像头id
	String cam_Uname = "";					  //摄像头用户名
	String cam_pw = "";						  //摄像头密�?

	private int printerStatusCode1=0;

	public void loadOption(String ip, String port, String camId, String camUsername, String camPw) {
		setPRINTER_IP(ip);
		setPRINTER_PORT(Integer.parseInt(port));
		setCam_id(camId);
		setCam_Uname(camUsername);
		setCam_pw(camPw);
	}

	public String getCam_id() {
		return cam_id;
	}

	public void setCam_id(String cam_id) {
		this.cam_id = cam_id;
	}

	public String getCam_Uname() {
		return cam_Uname;
	}

	public void setCam_Uname(String cam_Uname) {
		this.cam_Uname = cam_Uname;
	}

	public String getCam_pw() {
		return cam_pw;
	}

	public void setCam_pw(String cam_pw) {
		this.cam_pw = cam_pw;
	}
	
	
	public boolean isAutoPowerOff() {
		return isAutoPowerOff;
	}

	public void setAutoPowerOff(boolean isAutoPowerOff) {
		this.isAutoPowerOff = isAutoPowerOff;
	}
	
	
	public String getPRINTER_IP() {
		return PRINTER_IP;
	}

	public void setPRINTER_IP(String pRINTER_IP) {
		PRINTER_IP = pRINTER_IP;
	}

	public int getPRINTER_PORT() {
		return PRINTER_PORT;
	}

	public void setPRINTER_PORT(int pRINTER_PORT) {
		PRINTER_PORT = pRINTER_PORT;
	}

	public String getPingResult() {
		return pingResult;
	}
	

	public void setPingResult(String pingResult) {
		this.pingResult = pingResult;
	}

	public static String CMD_CHOOSE_FILE(String filePath) {
		return "M23 " + filePath;
	}
	
   //设置打印速度指令
	public static String CMD_SET_SPEED_PRINT(int speed) {
		// if(a>=0&&a<=300)

		int max = 300, min = 0;
		if (speed < min)
			speed = min;
		if (speed > max)
			speed = max;
		return "M220 S" + speed;
	}

	//设置风扇速度指令
	public static String CMD_SET_SPEED_FANS(int speed) {
		int max = 255, min = 0;
		if (speed < min)
			speed = min;
		if (speed > max)
			speed = max;
		return "M106 S" + speed;
	}

	//设置材料速度指令
	public static String CMD_SET_SPEED_MATERIAL(int speed) {
		int max = 120, min = 80;
		if (speed < min)
			speed = min;
		if (speed > max)
			speed = max;
		return "M221 S" + speed;
	}

    //设置喷头温度指令 e_no=0or1 分别代表喷头1 喷头2
	public static String CMD_SET_TEMP_E(int e_no, double temp) {
		if (e_no != 0 && e_no != 1)
			return null;

		int max = 350, min = 0;
		if (temp < min)
			temp = min;
		if (temp > max)
			temp = max;
		return "M104 T" + e_no + " S" + temp;
	}

	//设置热床温度指令
	public static String CMD_SET_TEMP_BED(double temp) {
		int max = 150, min = 0;
		if (temp < min)
			temp = min;
		if (temp > max)
			temp = max;

		return "M140 S" + temp;

	}

	//移轴指令
	public static String CMD_MOVE_AXIS(String direction ,String pace) {
		return "G91\rG1 "+direction+pace+"\rG90\r"; 
	}
	
	
	//喷头出料
	public static String CMD_MOVE_E(String eno, String pace,String acc) {
		return "G91\r"+eno+"\r G1 E"+pace+acc+"\rG90\r";
	}


	public ArrayList<String> getFiles() {
		return files;
	}

	public void setFiles(ArrayList<String> files) {
		this.files = files;
	}

	public int getPrinterStatusCode() {
		return printerStatusCode1;
	}

	public void setPrinterStatusCode(int printerStatusCode) {
		this.printerStatusCode1 = printerStatusCode;
	}
 

	public String getPrintingFile() {
		return printingFile;
	}

	public void setPrintingFile(String printingFile) {
		this.printingFile = printingFile;
	}

	public int getPrintingTime() {
		return printingTime;
	}

	public void setPrintingTime(int printingTime) {
		this.printingTime = printingTime;
	}

	
	public int getPrintingProcess() {
		return printingProcess;
	}

	
	
	public void setPrintingProcess(int printingProcess) {
		this.printingProcess = printingProcess;
	}

	/**
	 * 打印进行中�?�暂停都视为 “正在打印�??
	 * @return
	 */
	public boolean isPrinting() {
		return getPrinterStatusCode() == PRINTER_STATUS_PRINTING
				|| getPrinterStatusCode() == PRINTER_STATUS_PAUSING;
	}



	int speedPrint, // 打印速度
			speedFans, // 风扇速度�?
			speedMaterial;// 进料速度

	public int getSpeedPrint() {
		return speedPrint;
	}

	public int getSpeedFans() {
		return speedFans;
	}

	public void setSpeedFans(int speedFans) {
		this.speedFans = speedFans;
	}

	public int getSpeedMaterial() {
		return speedMaterial;
	}

	public void setSpeedMaterial(int speedMaterial) {
		this.speedMaterial = speedMaterial;
	}

	public void setSpeedPrint(int speedPrint) {
		this.speedPrint = speedPrint;
	}

	public int getTemp1() {
		return temp1;
	}

	public void setTemp1(int temp1) {
		this.temp1 = temp1;
	}

	public int getTemp1Target() {
		return temp1Target;
	}

	public void setTemp1Target(int temp1Target) {
		this.temp1Target = temp1Target;
	}

	public int getTemp2() {
		return temp2;
	}

	public void setTemp2(int temp2) {
		this.temp2 = temp2;
	}

	public int getTemp2Target() {
		return temp2Target;
	}

	public void setTemp2Target(int temp2Target) {
		this.temp2Target = temp2Target;
	}

	public int getTempBed() {
		return tempBed;
	}

	public void setTempBed(int tempBed) {
		this.tempBed = tempBed;
	}

	public int getTempBedTarget() {
		return tempBedTarget;
	}

	public void setTempBedTarget(int tempBedTarget) {
		this.tempBedTarget = tempBedTarget;
	}

	public String getFirmwareVersion() {
		return firmwareVersion;
	}

	public void setFirmwareVersion(String firmwareVersion) {
		this.firmwareVersion = firmwareVersion;
	}


}
